package cn.yinyu.queue.module.ecg.controller.admin.config;

import cn.yinyu.queue.framework.common.pojo.CommonResult;
import cn.yinyu.queue.module.ecg.controller.admin.config.vo.TimeslotVO;
import cn.yinyu.queue.module.ecg.controller.admin.queuesequence.vo.QueueSequenceSaveReqVO;
import cn.yinyu.queue.module.ecg.service.config.EcgConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

import static cn.yinyu.queue.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 业务配置")
@RestController
@RequestMapping("/ecg/biz-config")
@Validated
public class ECGConfigController {

    @Resource
    private EcgConfigService ecgConfigService;

    @GetMapping("/list-timeslot")
    @Operation(summary = "预约时间段列表")
    @PermitAll
    public CommonResult<List<LocalTime>> listTimeslot(@Valid @RequestBody QueueSequenceSaveReqVO createReqVO) {

        List<LocalTime> localTimeList = ecgConfigService.listTimeslot();
        List<TimeslotVO> timeslotVOList = new ArrayList<>();

        localTimeList.forEach( localTime -> {
            TimeslotVO timeslotVO = new TimeslotVO();
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm");
            timeslotVO.setLabel( localTime.format(dateTimeFormatter));
            timeslotVO.setValue( localTime.getHour()*100 + localTime.getMinute() );
            timeslotVOList.add( timeslotVO );
        });

        return success(ecgConfigService.listTimeslot());
    }
}
